<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Models\Test;
use App\Http\Models\User;
use App\Http\Models\Goods;

class TestController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {

    }

    public function index(Request $request){
        $view = $request->h? $request->h : 'index';
        return view("html/{$view}");
    }
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function saveData(Request $request)
    {
        $item = new Test;
        $item->col1 = $request->col1;
        $item->col2 = $request->col2;
        $item->col3 = $request->col3;

        $item->save();
        return json_encode(['code'=>0,'msg'=>'ok','data'=>$item]);
    }

    public function updateData(Request $request)
    {
        $item = Test::find($request->id);
        $item->col1 = $request->col1;
        $item->save();
        return json_encode(['code'=>0,'msg'=>'ok']);
    }

    public function getDetail(Request $request){
        $data = Test::where('col1',$request->col1)->first();
        return json_encode(['code'=>0,'msg'=>'ok','data'=>$data]);
    }

    //预约列表
    public function getList(Request $request)
    {

        // $todayCreate=User::whereDate('created_at','2018-07-30')->count();
        $shelfCount=Goods::where('userid',5)->count();
print_r($shelfCount);exit;
        $offset = $request->offset;
        $limit = $request->limit;
        $list = Test::where('col1',$request->col1)->where('col2',$request->col2)->orderBy('col1','desc')->offset($offset)->limit($limit)->get();
        return json_encode(['code'=>0,'msg'=>'ok','data'=>$list]);
    }
}
